package com.yc.baseProgram.jdk8;

import java.util.Optional;

import com.yc.entity.Student;

public class TestOptional {
	
	public static String getGender(Student student) {
		if (null == student) {
			return "Unkown";
		}
		return student.getName();

	}

	public static String getGender_new(Student student) {
		return Optional.ofNullable(student).map(u -> u.getName()).orElse("Unkown");

	}

	public static void main(String[] args) {
		TestOptional to = new TestOptional();
		
		Student s1 = new Student();
		s1.setName("aaa");
		Student s2 = null;
		
		System.out.println(to.getGender(s1));
		System.out.println(to.getGender(s2));
		

		System.out.println(to.getGender_new(s1));
		System.out.println(to.getGender_new(s2));
	}

}
